<template>
	<view class="columnbox wdh-100 content">
		<view class="info-box columnbox wdh-100">
			<view class="rowbox one-info spb">
				<view class="info-title">{{title}}</view>
				<!-- <view style="color: #dddddd;" class="set-btn">最多可填6个疾病</view> -->
			</view>
			<textarea v-model="content" class="info-input" style="width: 690rpx;" placeholder="请输入(逗号分隔)"></textarea>
		</view>
		<view class="info-box columnbox wdh-100">
			<view class="rowbox one-info spb">
				<view class="info-title">最近使用</view>
			</view>
			<view class="history-list">
				<view @click="addInfo(item)" class="one-box" v-for="(item,index) in recordList" :key='index'>
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="wdh-100" style="height: 200rpx;"></view>
		<view class="rowbox wdh-100 bottom-box">
			<view @click="saveInfo" class="rowbox send-btn wdh-100">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				recordList: [],
				type: '',
				name: '',
				title: '疾病诊断'
			};
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
				this.name = options.name
				if (options.name == 'bianbing') {
					if (options.type == 'zhongyao') {
						this.title = '辨病'
						uni.setNavigationBarTitle({
							title: '辨病'
						})
					} else {
						this.title = '疾病诊断'
						uni.setNavigationBarTitle({
							title: '疾病诊断'
						})
					}

				} else if (options.name == 'bianzheng') {
					this.title = '辨证'
					uni.setNavigationBarTitle({
						title: '辨证'
					})
				} else if (options.name == 'yizhu') {
					this.title = '医嘱'
					uni.setNavigationBarTitle({
						title: '医嘱'
					})
				} else if (options.name == 'zhusu') {
					this.title = '患者主诉'
					uni.setNavigationBarTitle({
						title: '患者主诉'
					})
				}
			}
			this.getRecord()
		},
		methods: {
			addInfo(v) {
				this.content = this.content == '' ? v.name : (this.content + ',' + v.name)
			},
			getRecord() {
				let url = '/doctor/jibingzd'
				if (this.type == 'zhongyao') {
					if (this.name == 'bianbing') {
						url = '/doctor/zybianbing'
					} else if (this.name == 'yizhu') {
						url = '/doctor/zyyizhu'
					} else {
						url = '/doctor/zybianzheng'
					}
				} else if (this.type == 'xiyao') {
					if (this.name == 'bianbing') {
						url = '/doctor/jibingzd'
					} else if (this.name == 'yizhu') {
						url = '/doctor/xyyizhu'
					} else {
						url = '/doctor/xyzhusu'
					}
				}
				this.$req.post(url, {
					doctorid: uni.getStorageSync('uid')
				}).then(res => {
					this.recordList = res.data.data
				})
			},
			addTem() {
				uni.navigateTo({
					url: './add'
				})
			},
			addDiseaseDia() {
				uni.navigateTo({
					url: '/packageA/yaofang/westMedicine/diseaseDiagnosis'
				})
			},
			saveInfo() {
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				if (this.type == 'zhongyao') {
					if (this.name == 'bianbing') {
						prevPage.$vm.bianbing = this.content
					} else if (this.name == 'bianzheng') {
						prevPage.$vm.bianzheng = this.content
					} else if (this.name == 'yizhu') {
						prevPage.$vm.title = this.content
					}
				} else if (this.type == 'xiyao') {
					if (this.name == 'bianbing') {
						prevPage.$vm.bianbing = this.content
					} else if (this.name == 'yizhu') {
						prevPage.$vm.yizhu = this.content
					} else if (this.name == 'zhusu') {
						prevPage.$vm.zhusu = this.content
					}
				} else {
					prevPage.$vm.jibing = this.content
				}
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background: #F5F8FB;
		justify-content: flex-start;
		font-family: PingFang SC;
	}

	.info-box {
		margin-bottom: 2rpx;
		background: #fff;
	}

	.one-info {
		width: 100%;
		padding: 32rpx 32rpx;
		background: #fff;
		font-size: 26rpx;

		.info-title {
			font-weight: bold;
			font-size: 26rpx;
			color: #202020;
			width: 190rpx;
			margin-right: 20rpx;
		}



		.code-box {
			width: calc(100% - 190rpx);
		}

		.code-input {
			text-align: left;
			font-size: 26rpx;
			width: 200rpx;
		}

		.code-btn {
			font-weight: bold;
		}
	}

	.info-input {
		width: calc(100% - 210rpx);
		text-align: left;
		font-size: 26rpx;
	}

	.set-btn {
		font-size: 24rpx;
		font-weight: bold;
	}

	.history-list {
		width: 100%;
		padding: 0 32rpx;
		box-sizing: border-box;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: flex-start;
	}

	.one-box {
		font-size: 24rpx;
		color: #595959;
		background: #f6f6f6;
		padding: 0 20rpx;
		border-radius: 4rpx;
		line-height: 50rpx;
		margin-bottom: 20rpx;
		margin-right: 20rpx;
	}
</style>
<style>
	.reg-pl {
		color: #939BA7;
	}
</style>